package com.neusoft.controller;

import com.neusoft.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {


    /*restTemplate
    * 参数
    * （url,实体 Map,Class<T> responseType)
    *
    * */
    @Autowired
    private RestTemplate restTemplate;

    //private static final String  REST_URL = "http://localhost:8001";

    //ribbon 实现应该是变量，通过Eureka服务来获取访问
    private static final String  REST_URL = "http://SPRINGCLUDE-PROVIDER-DEPT";

    @RequestMapping("/consumer/dept/add")
    public boolean add(Dept dept){

        return restTemplate.postForObject(REST_URL+"/dept/add",dept,Boolean.class);
    }

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable("id") int id){
        return restTemplate.getForObject(REST_URL+"/dept/queryById/"+id, Dept.class);
    }

    @RequestMapping("/consumer/dept/getAll")
    public List<Dept> query(){
        return restTemplate.getForObject(REST_URL+"/dept/queryAll",List.class);
    }

}
